package com.service.impl;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dao.MessgDao;
import com.dto.Message;
import com.service.MessageService;
import com.wxapi.WxApiCall.WxApiCall;
import com.wxapi.model.RequestModel;
@Service
public class MessageServiceImpl implements MessageService {

	@Autowired
	private  MessgDao mes;
	

	@Override// 
	public Message queryMess(String phone) {
		// TODO Auto-generated method stub
		return mes.queryMess(phone);
	}	


	@Override
	public int addmess(Message mess) {
		//你的数据访问层 怎么命名为 Messg
		String sources = "0123456789"; // 加上一些字母，就可以生成pc站的验证码了  
	    Random rand = new Random();  
	    StringBuffer flag = new StringBuffer();  
	    for (int j = 0; j < 6; j++)   
	    {  
	        flag.append(sources.charAt(rand.nextInt(9)) + "");  
	    }  
	   //将生成的验证码放入mess对象中
	    mess.setYzm(flag.toString());
		//这个地方到时候调用 短信平台
	    RequestModel model = new RequestModel();
		model.setGwUrl("");//https://way.jd.com/chonry/smsnotice
		model.setAppkey("649735d3c203ba51f23cf0bd5dce1870");
		Map queryMap = new HashMap();
		queryMap.put("sign","【创瑞云】"); //访问参数
		queryMap.put("mobile",mess.getPhone()); //访问参数
		queryMap.put("content","您的本次的验证码是："+mess.getYzm()+"。");  //访问参数
		model.setQueryParams(queryMap);
		WxApiCall call = new WxApiCall();
		call.setModel(model);
		call.request();
		
		/*if() {
			
		}*/
		return mes.addmess(mess);
	}

}
